/**
 * 
 */
package com.odontosis.view;

import java.lang.reflect.ParameterizedType;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.odontosis.as.OdontosisApplicationService;
import com.odontosis.view.cadastro.paciente.FormCadastroPaciente;

/**
 * Action principal do sistema.
 * 
 * @param T
 *            Classe de Application Service da ao.
 * @author Oto
 */
public abstract class OdontosisAction<T extends OdontosisApplicationService>
		extends DispatchAction {
	private static final String INFORMATION_MESSAGE = "INFORMATION_MESSAGE";
	private static final String ERRO_MENSAGEM_NAO_ENCONTRADA = "ERRO_MENSAGEM_NAO_ENCONTRADA";
	private static final String ERRO_DESCONHECIDO = "ERRO_DESCONHECIDO";

	private Class<?> classeAS;
	protected Log log = LogFactory.getLog(this.getClass());
	protected T service;

	@SuppressWarnings("unchecked")
	public OdontosisAction() {
		classeAS = (Class<?>) ((ParameterizedType) getClass()
				.getGenericSuperclass()).getActualTypeArguments()[0];
		log.debug("Classe de AS obtida do parmetro genrico: "
				+ classeAS.getName());
		try {
			service = (T) classeAS.newInstance();
			log.debug("AS instanciado: " + service.toString());
		} catch (Exception e) {
			log
					.error("No foi possivel instanciar a classe Application Service "
							+ classeAS.getName() + " para esta ao");
		}
	}

	/**
	 * Mtodo de ao quando parrametro no especificado.
	 */
	@Override
	protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.getInputForward();
	}


	

}
